/**
 * Created by nondo on 2017/7/14.
 */
var app = new Vue({
    el: '#app',
    data: function () {
        return {
            activeName: 'first',//tab初始化页面
            currentPage: 1,//分页初始化页面
            totalPage: 1,//分页总页数
            tableData: [],//table数据
            searchForm: {//搜索表单内容
                name: '',
                status: ''
            },
        }
    },
    methods: {
        /**
         * tab色彩处理方案
         */
        tableRowClassName: function (row, index) {
            if (row.status === 0) {
                return 'info-row';
            } else if (row.status === 3) {
                return 'positive-row';
            }
            return '';
        },
        /**
         * 分页处理
         */
        handleClick: function (tab, event) {
            console.log(tab, event);
        },
        /**
         * 搜索表单
         */
        onSearchSubmit: function () {
            this.getTableList(this.currentPage, app.searchForm);
        },
        /**
         * 分页-页码变动
         */
        handleSizeChange: function (val) {
            //console.log(`每页 ${val} 条`);
        },
        /**
         * 分页-当前页码
         */
        handleCurrentChange: function (val) {
            this.getTableList(val, []);
        }
    }
});
/**
 * 获取table内容
 * @param currentPage
 * @param searchForm
 */
app.getTableList = function (currentPage, searchForm) {
    $.ajax({
        url: '/admin/user/list',
        dataType: 'json',
        type: 'POST',
        headers: {
            'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
        },
        data: {
            page: currentPage,
            name: searchForm ? searchForm.name : '',
            status: searchForm ? searchForm.status : ''
        },
        success: function (data, textStatus, jqXHR) {
            console.log(data);
            //填充数据

            app.tableData = data.datas.data;
            //填充分页

            app.currentPage = data.datas.current_page;
            app.pageTotal = data.datas.total;
        },
        error: function (xhr, textStatus) {
            console.log('错误')
            console.log(xhr)
            console.log(textStatus)
        }
    });
};

app.getTableList(1);